//
//  MSHeroInfo.m
//  MagicSword
//
//  Created by Netease on 15/11/16.
//  Copyright © 2015年 Jonear. All rights reserved.
//

#import "MSHeroInfo.h"
#import "MSWeaponInfo.h"

@implementation MSHeroInfo

+ (NSDictionary *)getDictFromHeroInfo:(MSHeroInfo *)heroInfo {
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:@(heroInfo.MaxHP) forKey:@"MaxHP"];
    [dict setObject:@(heroInfo.Attack) forKey:@"Attack"];
    [dict setObject:@(heroInfo.Defense) forKey:@"Defense"];
    [dict setObject:@(heroInfo.Experience) forKey:@"Experience"];
    [dict setObject:@(heroInfo.Crit) forKey:@"Crit"];
    [dict setObject:@(heroInfo.DoubleHit) forKey:@"DoubleHit"];
    [dict setObject:@(heroInfo.Vampire) forKey:@"Vampire"];
    [dict setObject:@(heroInfo.MissValue) forKey:@"MissValue"];
    [dict setObject:@(heroInfo.level) forKey:@"level"];
    [dict setObject:@(heroInfo.isInFight) forKey:@"isInFight"];
    [dict setObject:@(heroInfo.type) forKey:@"type"];
    
    //背包
    NSMutableArray *weaponDictArray = [NSMutableArray array];
    for (MSWeaponInfo *info in heroInfo.weaponList) {
        [weaponDictArray addObject:[MSWeaponInfo getDictFromInfo:info]];
    }
    [dict setObject:weaponDictArray forKey:@"weaponList"];
    return dict;
}

+ (MSHeroInfo *)getHeroInfoFromDict:(NSDictionary *)dict {
    MSHeroInfo *info = [[MSHeroInfo alloc] init];
    info.MaxHP = [dict[@"MaxHP"] integerValue];
    info.Attack = [dict[@"Attack"] integerValue];
    info.Defense = [dict[@"Defense"] integerValue];
    info.Experience = [dict[@"Experience"] integerValue];
    info.Crit = [dict[@"Crit"] integerValue];
    info.DoubleHit = [dict[@"DoubleHit"] integerValue];
    info.Vampire = [dict[@"Vampire"] integerValue];
    info.MissValue = [dict[@"MissValue"] integerValue];
    info.level = [dict[@"level"] integerValue];
    info.isInFight = [dict[@"isInFight"] boolValue];
    info.type = [dict[@"type"] integerValue];
    
    //背包
    NSMutableArray *weaponArray = [NSMutableArray array];
    for (NSDictionary *dic in dict[@"weaponList"]) {
        [weaponArray addObject:[MSWeaponInfo getInfoFromDict:dic]];
    }
    info.weaponList = weaponArray;
    
    return info;
}

@end
